/* 
 *   Classname:  datapower.ExportToCSV
 * 
 *   Date       Developer   Description
 *   Nov 28, 2017    周成功              新建
 *
 */
package demo.database.show;

import java.sql.Connection;
import java.util.ArrayList;
import java.util.List;

import javax.sql.DataSource;

import com.titan.core.utils.data.FormatUtils;
import com.titan.core.utils.db.DBUtils;
import com.titan.core.utils.db.DataSourceUtils;
import com.titan.core.utils.db.JdbcUtils;
import com.titan.core.utils.db.RecordSet;
import com.titan.core.utils.file.CSVUtils;
import com.titan.core.utils.file.ClassUtils;
import com.titan.core.utils.file.FileUtils;

/**
 *
 *
 * @author 周成功
 *
 */
public class ShowTables {
    private static String rootPath  = null;
    private static String ip  = null;
    private static String port  = "1521";
    private static String dbname  = null;
    
    private static void localEnv() {
        ip  = "192.168.128.212";
        dbname = "orcl";
    }
    private static void serverEnv() {
        String ip  = "cch02017.harbin.ford.com";
        String dbname = "hrbsgts";
    }

    public static void main(String[] args) {
        Connection conn = null;
        try {
            localEnv();
//          serverEnv();
          
            String username = "hrbsgts";
            String password = "hrbsgts";
            String driver = "oracle.jdbc.driver.OracleDriver";
            String url = "jdbc:oracle:thin:@" + ip + ":" + port + ":" + dbname;
          
            DataSource datasource = DataSourceUtils.registerDataSource(null, driver, url, username, password, 5, 5);
            JdbcUtils.setDataSource(datasource);
            conn = datasource.getConnection();
            
            run(conn);
        } catch(Exception ex) {
            ex.printStackTrace();
        } finally {
            DBUtils.close(conn);
        }
    }
    private static void run(Connection conn) throws Exception {
        String sql = "select t.tname from tab t where t.tabtype='TABLE' and tname not in (SELECT object_name FROM user_recyclebin)";
        String[] values = DBUtils.getValues(conn, sql, new String[0]);
        for (int i = 0; i < values.length; i++) {
            System.out.println(FormatUtils.to4Digit(i) + "\t" + values[i]);
        }
    }
}
